source ~/.config/nvim/plugins.vim
set number
set nocompatible
syntax on
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set incsearch
set hlsearch
set backspace=indent,start,eol
set iskeyword+=-
set clipboard=unnamedplus
set fileencoding=utf-8
set encoding=utf-8
set conceallevel=0 "在markdown文件中可以看到``
set noundofile
set nobackup
set noswapfile
set ignorecase
set smartcase
set tabstop=2
set shiftwidth=2
set expandtab "tab键永远输入的是空格
set softtabstop=0 "关闭空格tab混用
autocmd FileType python set sw=4 ts=4
set cursorline
colorscheme gruvbox
set background=dark
set hidden
set autoindent
set list
silent set listchars lcs=tab:>-,trail:.
set scrolloff=3
set textwidth=0 "使用gq生效
set termguicolors
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set splitright
set splitbelow
set noshowmode
set showcmd
if has('nvim')
  set inccommand=split "仅支持:s替换
end
set wildmenu
set virtualedit=block
set shortmess+=c
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif "如果在退出时有修改, 则再次打开时自动跳转到修改的地方

"==== 按键映射
let mapleader=' '
nmap <leader>w :w<CR>
imap jk <ESC>
imap kj <ESC>
imap jj <ESC>
nmap ; :
vmap ; :
nmap <C-l> <C-w>l
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <TAB> :bn<CR>
iabbrev mian main
nmap <C-UP> :res +5<CR>
nmap <C-DOWN> :res -5<CR>
nmap <C-LEFT> :vertical resize-5<CR>
nmap <C-RIGHT> :vertical resize+5<CR>
nmap <silent> <leader>h :setlocal nohlsearch<CR>
"nmap <leader>sp <C-w>t<C-w>K
"nmap <leader>sv <C-w>t<C-w>H
"noremap <leader>srp <C-w>b<C-w>K
"noremap <leader>srv <C-w>b<C-w>H
nmap < <<
nmap > >>
imap <C-l> <RIGHT>
imap <C-h> <LEFT>
"nmap <space> <NOP>
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"

" nnoremap <c-j> /<+.\{-1,}+><cr>c/+>/e<cr>
" inoremap <c-j> <ESC>/<+.\{-1,}+><cr>c/+>/e<cr>
" inoremap <c-j> <ESC>/<++><cr>c/+>/e<cr>
autocmd BufEnter * silent! lcd %:p:h
autocmd BufNewFile * silent! 0r ~/.vim/templates/%:e.tpl
"autocmd FileType python map <buffer> <leader>r :w<CR>:exec '!python3' shellescape(@%, 1)<CR>
"autocmd Filetype python nnoremap <buffer> <leader>r :w<CR>:vert ter python3 "%"<CR>
"autocmd FileType python imap <buffer> <leader>r <esc>:w<CR>:exec '!python3' shellescape(@%, 1)<CR>
" Markdown
"
" autocmd Filetype markdown inoremap <buffer> ,f <Esc>/<++><CR>:nohlsearch<CR>"_c4l
" autocmd Filetype markdown inoremap <buffer> ,w <Esc>/ <++><CR>:nohlsearch<CR>"_c5l<CR>
" autocmd Filetype markdown inoremap <buffer> ,n ---<Enter><Enter>
" autocmd Filetype markdown inoremap <buffer> ,b **** <++><Esc>F*hi
" autocmd Filetype markdown inoremap <buffer> ,s ~~~~ <++><Esc>F~hi
" autocmd Filetype markdown inoremap <buffer> ,i ** <++><Esc>F*i
" autocmd Filetype markdown inoremap <buffer> ,d `` <++><Esc>F`i
" autocmd Filetype markdown inoremap <buffer> ,c ```<Enter><++><Enter>```<Enter><Enter><++><Esc>4kA
" autocmd Filetype markdown inoremap <buffer> ,m - [ ]
" autocmd Filetype markdown inoremap <buffer> ,p ![](<++>) <++><Esc>F[a
" autocmd Filetype markdown inoremap <buffer> ,a [](<++>) <++><Esc>F[a
" autocmd Filetype markdown inoremap <buffer> ,1 #<Space><Enter><++><Esc>kA
" autocmd Filetype markdown inoremap <buffer> ,2 ##<Space><Enter><++><Esc>kA
" autocmd Filetype markdown inoremap <buffer> ,3 ###<Space><Enter><++><Esc>kA
" autocmd Filetype markdown inoremap <buffer> ,4 ####<Space><Enter><++><Esc>kA
" autocmd Filetype markdown inoremap <buffer> ,l --------<Enter>
let g:neoterm_autoscroll = 1
autocmd TermOpen term://* startinsert
tnoremap <C-N> <C-\><C-N>
tnoremap <C-O> <C-\><C-N><C-O>
noremap <LEADER>r :call CompileRunGcc()<CR>
func! CompileRunGcc()
 exec "w"
 if &filetype == 'c'
  exec "!g++ % -o %<"
  exec "!time ./%<"
 elseif &filetype == 'cpp'
  set splitbelow
  exec "!g++ -std=c++11 % -Wall -o %<"
  :sp
  :res -15
  :term ./%<
 elseif &filetype == 'java'
  exec "!javac %"
  exec "!time java %<"
 elseif &filetype == 'sh'
  :!time bash %
 elseif &filetype == 'python'
  set splitbelow
  :sp
  :term python3 %
 elseif &filetype == 'html'
  silent! exec "!".g:mkdp_browser." % &"
 elseif &filetype == 'markdown'
  exec "InstantMarkdownPreview"
 elseif &filetype == 'tex'
  silent! exec "VimtexStop"
  silent! exec "VimtexCompile"
 elseif &filetype == 'dart'
  exec "CocCommand flutter.run -d ".g:flutter_default_device." ".g:flutter_run_args
  silent! exec "CocCommand flutter.dev.openDevLog"
 elseif &filetype == 'javascript'
  set splitbelow
  :sp
  :term export DEBUG="INFO,ERROR,WARNING"; node --trace-warnings .
 elseif &filetype == 'go'
  set splitbelow
  :sp
  :term go run .
 endif
endfunc
